package com.jnu.myfirstapplication;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class About extends AppCompatActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_about);

        ImageButton back=findViewById(R.id.about_back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setResult(200);
                finish();
            }
        });

        RadioGroup group1=findViewById(R.id.about_group1);
        group1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getApplicationContext(),"Now version is 1.0.23",Toast.LENGTH_SHORT).show();
            }
        });

        RadioGroup group2=findViewById(R.id.about_group2);
        group2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Uri uri = Uri.parse("https://gitee.com/emiya0415/android-mobile-development/tree/final_assignment_change");
                startActivity(new Intent(Intent.ACTION_VIEW,uri));
            }
        });
        RadioGroup group3=findViewById(R.id.about_group3);
        group3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Uri uri = Uri.parse("https://gitee.com/emiya0415/android-mobile-development/issues");
                startActivity(new Intent(Intent.ACTION_VIEW,uri));
            }
        });
        RadioGroup group4=findViewById(R.id.about_group4);
        Context mContext=About.this;
        group4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog alert = null;
                AlertDialog.Builder builder = new AlertDialog.Builder(mContext,R.style.AlertDialogCustom);
                WebView wv = new WebView(About.this);
                wv.loadUrl("file:///android_asset/web/license.html");
                wv.setWebViewClient(new WebViewClient() {
                    @SuppressWarnings("deprecation")
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        view.loadUrl(url);
                        return true;
                    }

                    @TargetApi(Build.VERSION_CODES.N)
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                        final Uri uri = request.getUrl();
                        view.loadUrl(uri.toString());
                        return true;
                    }
                });
                alert = builder.setIcon(R.drawable.jinan)
                        .setTitle("License：")
                        .setView(wv)
//                        .setMessage(R.menu.)
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        }).create();             //创建AlertDialog对象
                alert.show();                    //显示对话框
            }
        });
        RadioGroup group5=findViewById(R.id.about_group5);
        group5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog alert = null;
                AlertDialog.Builder builder = new AlertDialog.Builder(mContext,R.style.AlertDialogCustom);
                WebView wv = new WebView(About.this);
                wv.loadUrl("file:///android_asset/web/privacy_policy.html");
                wv.setWebViewClient(new WebViewClient() {
                    @SuppressWarnings("deprecation")
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        view.loadUrl(url);
                        return true;
                    }

                    @TargetApi(Build.VERSION_CODES.N)
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                        final Uri uri = request.getUrl();
                        view.loadUrl(uri.toString());
                        return true;
                    }
                });
                alert = builder.setIcon(R.drawable.jinan)
                        .setTitle("Privacy Policy：")
                        .setView(wv)
//                        .setMessage(R.menu.)
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        }).create();             //创建AlertDialog对象
                alert.show();                    //显示对话框
            }
        });
        RadioGroup group6=findViewById(R.id.about_group6);
        group6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog alert = null;
                AlertDialog.Builder builder = new AlertDialog.Builder(mContext,R.style.AlertDialogCustom);
                WebView wv = new WebView(About.this);
                wv.loadUrl("file:///android_asset/web/termOfService_zh.html");
                wv.setWebViewClient(new WebViewClient() {
                    @SuppressWarnings("deprecation")
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        view.loadUrl(url);
                        return true;
                    }

                    @TargetApi(Build.VERSION_CODES.N)
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                        final Uri uri = request.getUrl();
                        view.loadUrl(uri.toString());
                        return true;
                    }
                });
                alert = builder.setIcon(R.drawable.jinan)
                        .setTitle("Term of Service：")
                        .setView(wv)
//                        .setMessage(R.menu.)
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        }).create();             //创建AlertDialog对象
                alert.show();                    //显示对话框
            }
        });
    }
}